#ifndef BSWAP_H
#define BSWAP_H

#include <endian.h>
#include <byteswap.h>

#if __BYTE_ORDER == __LITTLE_ENDIAN
static inline uint16_t be16_to_cpu(uint16_t x) { return bswap_16(x); }
static inline uint32_t be32_to_cpu(uint32_t x) { return bswap_32(x); }
static inline uint64_t be64_to_cpu(uint64_t x) { return bswap_64(x); }
static inline uint16_t cpu_to_be16(uint16_t x) { return bswap_16(x); }
static inline uint32_t cpu_to_be32(uint32_t x) { return bswap_32(x); }
static inline uint64_t cpu_to_be64(uint64_t x) { return bswap_64(x); }

static inline uint16_t le16_to_cpu(uint16_t x) { return x; }
static inline uint32_t le32_to_cpu(uint32_t x) { return x; }
static inline uint64_t le64_to_cpu(uint64_t x) { return x; }
static inline uint16_t cpu_to_le16(uint16_t x) { return x; }
static inline uint32_t cpu_to_le32(uint32_t x) { return x; }
static inline uint64_t cpu_to_le64(uint64_t x) { return x; }
#else
static inline uint16_t be16_to_cpu(uint16_t x) { return x; }
static inline uint32_t be32_to_cpu(uint32_t x) { return x; }
static inline uint64_t be64_to_cpu(uint64_t x) { return x; }
static inline uint16_t cpu_to_be16(uint16_t x) { return x; }
static inline uint32_t cpu_to_be32(uint32_t x) { return x; }
static inline uint64_t cpu_to_be64(uint64_t x) { return x; }

static inline uint16_t le16_to_cpu(uint16_t x) { return bswap_16(x); }
static inline uint32_t le32_to_cpu(uint32_t x) { return bswap_32(x); }
static inline uint64_t le64_to_cpu(uint64_t x) { return bswap_64(x); }
static inline uint16_t cpu_to_le16(uint16_t x) { return bswap_16(x); }
static inline uint32_t cpu_to_le32(uint32_t x) { return bswap_32(x); }
static inline uint64_t cpu_to_le64(uint64_t x) { return bswap_64(x); }
#endif

#endif